package vista;

import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import java.awt.Color;
import java.awt.Font;

import bean.*;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class VistaFrase extends javax.swing.JFrame {
	private JPanel panPanel;
	private JButton btnModificar;
	private JButton btnPasar;
	private JLabel lblTitulo;
	private JLabel lblId;
	private JLabel lblFrase;
	private JTextFieldValidator txtId;
	private JTextFieldValidator txtFrase;
	private JButton btnIncluir;
	private JButton btnCancelar;
	private JButton btnEliminarFila;
	private JTable tblFrases;
	private JScrollPane scpListado;
	private JPanel panPrincipal;
	private JTextField txtfila;

	public VistaFrase() {
		super();
		initGUI();		
		initTabla();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			this.setTitle("Registrar Frase");
			{
				lblTitulo = new JLabel();
				getContentPane().add(lblTitulo);
				lblTitulo.setText("Frases");
				lblTitulo.setBounds(34, 0, 310, 32);
				lblTitulo.setFont(new java.awt.Font("DejaVu Sans",1,16));
			}
			
			
			{
				panPanel = new JPanel();
				getContentPane().add(panPanel);
				panPanel.setBounds(34, 29, 372, 133);
				panPanel.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				panPanel.setLayout(null);
				panPanel.setOpaque(false);
				{
					lblId = new JLabel();
					panPanel.add(lblId);
					lblId.setText("Id");
					lblId.setBounds(24, 28, 64, 15);
					lblId.setFont(new java.awt.Font("Dialog",0,12));
				}
				{
					txtId = new JTextFieldValidator(8,JTextFieldValidator.SOLO_NUMEROS);
					panPanel.add(txtId);
					txtId.setBounds(87, 25, 119, 22);
				}							
				{
					lblFrase = new JLabel();
					panPanel.add(lblFrase);
					lblFrase.setText("Frase");
					lblFrase.setBounds(23, 62, 79, 15);
					lblFrase.setFont(new java.awt.Font("Dialog",0,12));
				}
				{
					txtFrase = new JTextFieldValidator();
					panPanel.add(txtFrase);
					txtFrase.setMaximaLongitud(50);
					txtFrase.setTipoCaracteresPermitidos(JTextFieldValidator.LETRAS_Y_ESPACIOS);
					txtFrase.setBounds(87, 60, 265, 22);
				}				
				
				}			

			{
				btnIncluir = new JButton();
				getContentPane().add(btnIncluir);
				btnIncluir.setText("Incluir");
				btnIncluir.setBounds(432, 29, 108, 29);
			}
			{
				btnCancelar = new JButton();
				getContentPane().add(btnCancelar);
			
				btnCancelar.setText("Cancelar");
				btnCancelar.setBounds(432, 63, 108, 29);				
			}

//			pack();
//			this.setVisible(true);
//			
//			//registrarControlador();
//			
//			this.setSize(593, 331);
			//registrarControlador();
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("static-access")
	public JTable getTabla() {
		if (tblFrases == null) {
			
			String[] encabezado = {"Id","Descripcion","Nivel"};
			
			String[][] data = {{"","",""},{"","",""},{"","",""}};
			
			
			tblFrases= new JTable(data,encabezado);
			
			
			JTableHeader anHeader = tblFrases.getTableHeader();
			anHeader.setForeground(new Color(0).WHITE);
			anHeader.setBackground(new Color(0,64,128));
			anHeader.setFont(new Font("Arial",Font.BOLD,12));
			tblFrases.setFont(new Font("Arial",Font.BOLD,12));
			tblFrases.setShowGrid(true);
			
		
		}
		return tblFrases;
	}

	private void initTabla() {
		try {
			
			{
				panPrincipal = new JPanel();
				getContentPane().add(panPrincipal);
				getContentPane().add(getBtnEliminarFila());
				getContentPane().add(getBtnPasar());
				getContentPane().add(getJButton1());
				panPrincipal.setBounds(34, 173, 372, 114);
				panPrincipal.setLayout(null);
				{
					scpListado = new JScrollPane();
					panPrincipal.add(scpListado);
					scpListado.setBounds(3, 5, 361, 103);
					{
						tblFrases = new JTable();
						scpListado.setViewportView(tblFrases);
						tblFrases.setBounds(3, 37, 354, 48);
						tblFrases.setPreferredSize(new java.awt.Dimension(353, 94));
						
						
					}
				}
			}

			pack();
			this.setSize(613, 337);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void setResultados(AbstractTableModel abstractTableModel) {
		tblFrases.setModel(abstractTableModel);
	}

	
	public void addListener(ActionListener actionListener) {
		btnIncluir.addActionListener(actionListener);
		btnCancelar.addActionListener(actionListener);
		btnPasar.addActionListener(actionListener);
		btnModificar.addActionListener(actionListener);
		btnEliminarFila.addActionListener(actionListener);
	}

	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	
	
	public JTextFieldValidator getTxtId() {
		return txtId;
	}

	public void setTxtId(JTextFieldValidator txtId) {
		this.txtId = txtId;
		txtId.setEnabled(false);
		txtId.setBackground(new java.awt.Color(255,255,128));
	}

	public JTextFieldValidator getTxtFrase() {
		return txtFrase;
	}

	public void setTxtFrase(JTextFieldValidator txtFrase) {
		this.txtFrase = txtFrase;
	}

	public JButton getBtnIncluir() {
		return btnIncluir;
	}

	public void setBtnIncluir(JButton btnIncluir) {
		this.btnIncluir = btnIncluir;
	}

	public JButton getBtnCancelar() {
		return btnCancelar;
	}

	public void setBtnCancelar(JButton btnCancelar) {
		this.btnCancelar = btnCancelar;
	}



	public void setTxtNivel(JTextField txtNivel) {
	}

	public void borrarDatos()
	{
		txtId.setText("");
		txtFrase.setText("");

				
	}
	
		
	public JTextField getTxtFila() {
		if(txtfila == null) {
			txtfila = new JTextField();
			txtfila.setBounds(451, 21, 38, 23);
		}
		return txtfila;
	}
	
	private JButton getBtnEliminarFila() {
		if(btnEliminarFila == null) {
			btnEliminarFila = new JButton();
			btnEliminarFila.setText("Eliminar");
			btnEliminarFila.setBounds(432, 130, 108, 23);
		}
		return btnEliminarFila;
	}
	
	public JButton getBtnModificar() {
		return btnModificar;
	}

	public void setBtnModificar(JButton btnModificar) {
		this.btnModificar = btnModificar;
	}

	public void setBtnPasar(JButton btnPasar) {
		this.btnPasar = btnPasar;
	}

	public void setBtnEliminarFila(JButton btnEliminarFila) {
		this.btnEliminarFila = btnEliminarFila;
	}

	private JButton getBtnPasar() {
		if(btnPasar == null) {
			btnPasar = new JButton();
			btnPasar.setText("Pasar");
			btnPasar.setBounds(432, 173, 108, 23);
		}
		return btnPasar;
	}
	
	private JButton getJButton1() {
		if(btnModificar == null) {
			btnModificar = new JButton();
			btnModificar.setText("Modificar");
			btnModificar.setBounds(432, 96, 108, 29);
			//btnModificar.addActionListener(actionListener);
		}
		return btnModificar;
	}

}
